package com.javaProject.controller;

import com.javaProject.dto.R;
import com.javaProject.entity.Message;
import com.javaProject.service.MessageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@Tag(name="消息接口",description = "这个接口的目的主要用于增删改查")
public class messageController {
    @Autowired
    private MessageService messageService;


    @PostMapping("/message/sendAllTeacher")
    @Operation(summary = "给所有老师发送消息",description = "需要发送的主要内容")
    @Parameter(name = "content",description = "主要内容",deprecated = true)
    public R sendAllTeacher(@RequestBody Message message){
        return messageService.sendAllteacher(message);
    }

    @PostMapping("/message/sendAllStudent")
    @Operation(summary = "给所有学生发送消息",description = "需要发送的主要内容,标题")
    @Parameters({
            @Parameter(name = "title",description = "标题",deprecated = true),
            @Parameter(name = "content",description = "主要内容",deprecated = true)
    })
    public R sendAllStudent(@RequestBody Message message){
        return messageService.sendAllStudent(message);
    }

    @PostMapping("/message/sendMessage")
    @Operation(summary = "发送单条消息",description = "需要发送接受者username和主要内容,标题")
    @Parameters({
            @Parameter(name = "recipient_id",description = "接收者id",deprecated = true),
            @Parameter(name = "title",description = "标题",deprecated = true),
            @Parameter(name = "content",description = "主要内容",deprecated = true)
    })
    public R sendMessage(@RequestBody Message message){
        return messageService.sendMessage(message);
    }


    @PostMapping("/message/getOneAllMessage")
    @Operation(summary = "查询个人消息",description = "需要接收者id")
    public List<Message> getOneAllMessage(@RequestBody Message message){
        return messageService.getOneAllMessage(message);
    }

    @GetMapping("/massage")
    @Operation(summary = "修改已读状态",description = "需要isReand")
    @Parameter(name = "massage_id",description = "消息id",deprecated = true)
    public R isRead(int massage_id){
        Message message = new Message();
        message.setMessageId(massage_id);
        return messageService.isReadMessage(message);
    }



}
